package com.wuzf.controller;


import com.wuzf.common.entity.CommonResult;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/lb")
public class PaymentHystrixController {


    @PostMapping("/ok")
    public CommonResult ok() {

        CommonResult<String> commonResult = new CommonResult<>(0, "成功");
        return commonResult;
    }


    @PostMapping("/error/{id}")
    public CommonResult error(@PathVariable("id") Integer id) {
        try {
            int i = 10 / id;
        } catch (Exception e) {
            throw new RuntimeException("失败了");
        }
        return new CommonResult<>(0, "成功");
    }


    @PostMapping("/timeout")
    public CommonResult timeout() {

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return new CommonResult<>(0, "成功");
    }

    @GetMapping("/hystrix/timeout/{id}")
    String paymentInfo_TimeOut(@PathVariable("id") Integer id) {

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "success";
    }
}
